package com.example.ut.controller;

import com.example.ut.controller.request.CreateStudentRequest;
import com.example.ut.controller.response.CreateStudentResponse;
import com.example.ut.mapper.StudentMapper;
import com.example.ut.service.StudentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("students")
@RequiredArgsConstructor
public class StudentController {
    private final StudentService studentService;

    @PostMapping
    public CreateStudentResponse addStudent(@Valid CreateStudentRequest request) {
        boolean isInsertSuccess = studentService.add(StudentMapper.INSTANCE.toDTO(request));
        if (isInsertSuccess) {
            return CreateStudentResponse.builder().message("success").build();
        }
        return CreateStudentResponse.builder().message("fail").build();
    }
}
